package com.pulaien.shop.controller;

import com.pulaien.common.core.domain.AjaxResult;
import com.pulaien.system.domain.StorageBill;
import com.pulaien.system.domain.dto.StorageOrderPayParam;
import com.pulaien.system.service.IStorageBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

//仓储单
@Slf4j
@RestController
@RequestMapping("/shop/storageOrder")
@Api(tags = "仓储单")
public class ShopStorageOrderController {

    @Autowired
    private IStorageBillService storageBillService;


    /**
     * 获取仓储账单
     */
    @ApiOperation(value = "获取仓储账单详情")
    @GetMapping(value = "/getBill/{orderId}")
    public AjaxResult selectByOrderId(@PathVariable("orderId") Long orderId)
    {
        List<StorageBill> list = storageBillService.selectByOrderId(orderId);
        return AjaxResult.success(list);
    }


    @ApiOperation("支付")
    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult pay(@RequestBody StorageOrderPayParam storageOrderPayParam) {
        return storageBillService.pay(storageOrderPayParam);
    }

    /**
     * PayPal 支付成功 回调
     * @param paymentId
     * @param payerId
     */
    @GetMapping("/payPalSuccess")
    public AjaxResult payPalSuccess(@RequestParam("orderId") String orderId, @RequestParam("paymentId") String paymentId, @RequestParam("PayerID") String payerId) {
        return storageBillService.payPalSuccess(orderId, paymentId, payerId);
    }

    /**
     * paypal 回调 取消支付
     * @throws IOException
     */
    @GetMapping("/payPalCancel")
    public AjaxResult payPalCancel(@RequestParam("orderId") String orderId){
        return storageBillService.payPalCancel(orderId);
    }

}
